//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package javax.vpncrypto.spec;

import java.security.MessageDigest;
import java.security.spec.KeySpec;
import java.util.Locale;
import javax.vpncrypto.SecretKey;

public class SecretKeySpec implements KeySpec, SecretKey {
    private static final long serialVersionUID = 6577238317307289933L;
    private byte[] key;
    private String algorithm;

    public SecretKeySpec(byte[] var1, String var2) {
        if (var1 != null && var2 != null) {
            if (var1.length == 0) {
                throw new IllegalArgumentException("Empty key");
            } else {
                this.key = (byte[])var1.clone();
                this.algorithm = var2;
            }
        } else {
            throw new IllegalArgumentException("Missing argument");
        }
    }

    public SecretKeySpec(byte[] var1, int var2, int var3, String var4) {
        if (var1 != null && var4 != null) {
            if (var1.length == 0) {
                throw new IllegalArgumentException("Empty key");
            } else if (var1.length - var2 < var3) {
                throw new IllegalArgumentException("Invalid offset/length combination");
            } else if (var3 < 0) {
                throw new ArrayIndexOutOfBoundsException("len is negative");
            } else {
                this.key = new byte[var3];
                System.arraycopy(var1, var2, this.key, 0, var3);
                this.algorithm = var4;
            }
        } else {
            throw new IllegalArgumentException("Missing argument");
        }
    }

    public String getAlgorithm() {
        return this.algorithm;
    }

    public String getFormat() {
        return "RAW";
    }

    public byte[] getEncoded() {
        return (byte[])this.key.clone();
    }

    public int hashCode() {
        int var1 = 0;

        for(int var2 = 1; var2 < this.key.length; ++var2) {
            var1 += this.key[var2] * var2;
        }

        return this.algorithm.equalsIgnoreCase("TripleDES") ? var1 ^ "desede".hashCode() : var1 ^ this.algorithm.toLowerCase(Locale.ENGLISH).hashCode();
    }

    public boolean equals(Object var1) {
        if (this == var1) {
            return true;
        } else if (!(var1 instanceof SecretKey)) {
            return false;
        } else {
            String var2 = ((SecretKey)var1).getAlgorithm();
            if (var2.equalsIgnoreCase(this.algorithm) || var2.equalsIgnoreCase("DESede") && this.algorithm.equalsIgnoreCase("TripleDES") || var2.equalsIgnoreCase("TripleDES") && this.algorithm.equalsIgnoreCase("DESede")) {
                byte[] var3 = ((SecretKey)var1).getEncoded();
                return MessageDigest.isEqual(this.key, var3);
            } else {
                return false;
            }
        }
    }
}
